import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { OrderApi } from '#/api/spa/order/order/index';

import { getDictOptions, getRangePickerDefaultProps } from '#/utils';
import { DICT_SPA_TYPE } from '#/utils/dictSpa';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'orderCode',
      label: '订单编码',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入订单编码',
      },
    },
    {
      fieldName: 'bookingId',
      label: '预约ID',
      component: 'Input',
      componentProps: {
        placeholder: '请输入预约ID',
      },
    },
    {
      fieldName: 'userId',
      label: '用户ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入用户ID',
      },
    },
    {
      fieldName: 'handCardId',
      label: '手牌ID',
      component: 'Input',
      componentProps: {
        placeholder: '请输入手牌ID',
      },
    },
    {
      fieldName: 'handCardNumber',
      label: '手牌号码',
      component: 'Input',
      componentProps: {
        placeholder: '请输入手牌号码',
      },
    },
    {
      fieldName: 'totalAmount',
      label: '总金额',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入总金额',
      },
    },
    {
      fieldName: 'discountAmount',
      label: '优惠金额',
      component: 'Input',
      componentProps: {
        placeholder: '请输入优惠金额',
      },
    },
    {
      fieldName: 'payableAmount',
      label: '应付金额',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入应付金额',
      },
    },
    {
      fieldName: 'pointsUsed',
      label: '使用积分',
      component: 'Input',
      componentProps: {
        placeholder: '请输入使用积分',
      },
    },
    {
      fieldName: 'pointsEarned',
      label: '获得积分',
      component: 'Input',
      componentProps: {
        placeholder: '请输入获得积分',
      },
    },
    {
      fieldName: 'payStatus',
      label: '支付状态',
      rules: 'required',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'payMethod',
      label: '支付方式',
      component: 'Input',
      componentProps: {
        placeholder: '请输入支付方式',
      },
    },
    {
      fieldName: 'payTime',
      label: '支付时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'transactionNo',
      label: '第三方交易号',
      component: 'Input',
      componentProps: {
        placeholder: '请输入第三方交易号',
      },
    },
    {
      fieldName: 'startTime',
      label: '开始时间',
      rules: 'required',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'endTime',
      label: '结束时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'durationMinutes',
      label: '总时长(分钟)',
      component: 'Input',
      componentProps: {
        placeholder: '请输入总时长(分钟)',
      },
    },
    {
      fieldName: 'status',
      label: '订单状态',
      rules: 'required',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'cancelReason',
      label: '取消原因',
      component: 'Input',
      componentProps: {
        placeholder: '请输入取消原因',
      },
    },
    {
      fieldName: 'notes',
      label: '备注',
      component: 'Input',
      componentProps: {
        placeholder: '请输入备注',
      },
    },
    {
      fieldName: 'groupId',
      label: '集团ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入集团ID',
      },
    },
    {
      fieldName: 'storeId',
      label: '门店ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入门店ID',
      },
    },
    {
      fieldName: 'orgId',
      label: '组织ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入组织ID',
      },
    },
    {
      fieldName: 'orderType',
      label: '订单类型',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择订单类型',
      },
    },
    {
      fieldName: 'orderSource',
      label: '订单来源',
      component: 'Input',
      componentProps: {
        placeholder: '请输入订单来源',
      },
    },
    {
      fieldName: 'expectedCompletionTime',
      label: '预期完成时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'actualCompletionTime',
      label: '实际完成时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'serviceQualityScore',
      label: '服务质量评分',
      component: 'Input',
      componentProps: {
        placeholder: '请输入服务质量评分',
      },
    },
    {
      fieldName: 'customerSatisfactionScore',
      label: '客户满意度评分',
      component: 'Input',
      componentProps: {
        placeholder: '请输入客户满意度评分',
      },
    },
    {
      fieldName: 'urgentFlag',
      label: '是否加急',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'boolean'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'vipLevel',
      label: 'VIP等级',
      component: 'Input',
      componentProps: {
        placeholder: '请输入VIP等级',
      },
    },
    {
      fieldName: 'scope',
      label: '作用域',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入作用域',
      },
    },
    {
      fieldName: 'scopeRef',
      label: '作用域引用',
      component: 'Input',
      componentProps: {
        placeholder: '请输入作用域引用',
      },
    },
    {
      fieldName: 'scopeRefTenantId',
      label: '',
      component: 'Input',
      componentProps: {
        placeholder: '请输入',
      },
    },
    {
      fieldName: 'scopeRefGroupId',
      label: '',
      component: 'Input',
      componentProps: {
        placeholder: '请输入',
      },
    },
    {
      fieldName: 'scopeRefStoreId',
      label: '',
      component: 'Input',
      componentProps: {
        placeholder: '请输入',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'orderCode',
      label: '订单编码',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入订单编码',
      },
    },
    {
      fieldName: 'bookingId',
      label: '预约ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入预约ID',
      },
    },
    {
      fieldName: 'userId',
      label: '用户ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入用户ID',
      },
    },
    {
      fieldName: 'handCardId',
      label: '手牌ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入手牌ID',
      },
    },
    {
      fieldName: 'handCardNumber',
      label: '手牌号码',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入手牌号码',
      },
    },

    {
      fieldName: 'payStatus',
      label: '支付状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择支付状态',
      },
    },
    {
      fieldName: 'payMethod',
      label: '支付方式',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入支付方式',
      },
    },
    {
      fieldName: 'payTime',
      label: '支付时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'transactionNo',
      label: '第三方交易号',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入第三方交易号',
      },
    },
    {
      fieldName: 'startTime',
      label: '开始时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'endTime',
      label: '结束时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },

    {
      fieldName: 'status',
      label: '订单状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择订单状态',
      },
    },

    {
      fieldName: 'groupId',
      label: '集团ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入集团ID',
      },
    },
    {
      fieldName: 'storeId',
      label: '门店ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入门店ID',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'orgId',
      label: '组织ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入组织ID',
      },
    },
    {
      fieldName: 'orderType',
      label: '订单类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择订单类型',
      },
    },
    {
      fieldName: 'orderSource',
      label: '订单来源',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入订单来源',
      },
    },
    {
      fieldName: 'expectedCompletionTime',
      label: '预期完成时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'actualCompletionTime',
      label: '实际完成时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'serviceQualityScore',
      label: '服务质量评分',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入服务质量评分',
      },
    },
    {
      fieldName: 'customerSatisfactionScore',
      label: '客户满意度评分',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入客户满意度评分',
      },
    },
    {
      fieldName: 'urgentFlag',
      label: '是否加急',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'boolean'),
        placeholder: '请选择是否加急',
      },
    },
    {
      fieldName: 'vipLevel',
      label: 'VIP等级',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入VIP等级',
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<OrderApi.Order>['columns'] {
  return [
    {
      field: 'id',
      title: '主键ID',
      minWidth: 120,
    },
    {
      field: 'orderCode',
      title: '订单编码',
      minWidth: 120,
    },
    {
      field: 'bookingId',
      title: '预约ID',
      minWidth: 120,
    },
    {
      field: 'userId',
      title: '用户ID',
      minWidth: 120,
    },
    {
      field: 'handCardId',
      title: '手牌ID',
      minWidth: 120,
    },
    {
      field: 'handCardNumber',
      title: '手牌号码',
      minWidth: 120,
    },
    {
      field: 'totalAmount',
      title: '总金额',
      minWidth: 120,
    },
    {
      field: 'discountAmount',
      title: '优惠金额',
      minWidth: 120,
    },
    {
      field: 'payableAmount',
      title: '应付金额',
      minWidth: 120,
    },
    {
      field: 'pointsUsed',
      title: '使用积分',
      minWidth: 120,
    },
    {
      field: 'pointsEarned',
      title: '获得积分',
      minWidth: 120,
    },
    {
      field: 'payStatus',
      title: '支付状态',
      minWidth: 120,
    },
    {
      field: 'payMethod',
      title: '支付方式',
      minWidth: 120,
    },
    {
      field: 'payTime',
      title: '支付时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'transactionNo',
      title: '第三方交易号',
      minWidth: 120,
    },
    {
      field: 'startTime',
      title: '开始时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'endTime',
      title: '结束时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'durationMinutes',
      title: '总时长(分钟)',
      minWidth: 120,
    },
    {
      field: 'status',
      title: '订单状态',
      minWidth: 120,
    },
    {
      field: 'cancelReason',
      title: '取消原因',
      minWidth: 120,
    },
    {
      field: 'notes',
      title: '备注',
      minWidth: 120,
    },
    {
      field: 'groupId',
      title: '集团ID',
      minWidth: 120,
    },
    {
      field: 'storeId',
      title: '门店ID',
      minWidth: 120,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'orgId',
      title: '组织ID',
      minWidth: 120,
    },
    {
      field: 'orderType',
      title: '订单类型',
      minWidth: 120,
    },
    {
      field: 'orderSource',
      title: '订单来源',
      minWidth: 120,
    },
    {
      field: 'expectedCompletionTime',
      title: '预期完成时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'actualCompletionTime',
      title: '实际完成时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'serviceQualityScore',
      title: '服务质量评分',
      minWidth: 120,
    },
    {
      field: 'customerSatisfactionScore',
      title: '客户满意度评分',
      minWidth: 120,
    },
    {
      field: 'urgentFlag',
      title: '是否加急',
      minWidth: 120,
    },
    {
      field: 'vipLevel',
      title: 'VIP等级',
      minWidth: 120,
    },
    {
      field: 'scope',
      title: '作用域',
      minWidth: 120,
    },
    {
      field: 'scopeRef',
      title: '作用域引用',
      minWidth: 120,
    },
    {
      field: 'scopeRefTenantId',
      title: '',
      minWidth: 120,
    },
    {
      field: 'scopeRefGroupId',
      title: '',
      minWidth: 120,
    },
    {
      field: 'scopeRefStoreId',
      title: '',
      minWidth: 120,
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
